﻿using CDSysLDManageProject.BYDTableAdapters;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace CDSysLDManageProject
{
    public partial class FormCurrentTask : Form
    {
        tbl_LDTaskListTableAdapter ldtask = new tbl_LDTaskListTableAdapter();
        DataTable task = new DataTable();
        public FormCurrentTask()
        {
            InitializeComponent();
            dgvCurrentTask.AutoGenerateColumns = false;
            task.Columns.Add("trayno");
            task.Columns.Add("recipeid");
            task.Columns.Add("fromlocation");
            task.Columns.Add("tolocation");
            task.Columns.Add("taskpriority");
            task.Columns.Add("createby");
            task.Columns.Add("ctime");
        }
        
        

        private void button1_Click(object sender, EventArgs e)
        {
            string trayno = tbxtrayno.Text;
            
            refreshQuery(trayno);
        }

        private void button2_Click(object sender, EventArgs e)
        {

             StaticArg.CheckStatus = "open";
            FormClosedCheck cc = new FormClosedCheck();
            cc.ShowDialog();

            if (StaticArg.CheckStatus == "close")
            {

                try
                {
                    
                        int keyid = int.Parse(dgvCurrentTask.SelectedRows[0].Cells["keyid"].Value.ToString());
                        if (MessageBox.Show(this, "是否要删除选中的任务", "提示信息", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                        {
                            ldtask.DeleteByKeyid(keyid);
                        }
                        else
                        {

                        }
                        string trayno = tbxtrayno.Text;

                        refreshQuery(trayno);
                   
                    
                }
                catch (Exception)
                {

                    MessageBox.Show("请正确选择要删除的记录!");
                }
               
            }
            else
            {
                
            }

           
        }
        public void refreshQuery(string trayno)
        {
            if (string.IsNullOrEmpty(trayno))
            {
                if (checkboxin.Checked == true && checkboxout.Checked == true)
                {
                    task = ldtask.GetTaskList();
                    dgvCurrentTask.DataSource = task;
                }
                else if (checkboxin.Checked)
                {
                    task = ldtask.GetInTaskList();
                    dgvCurrentTask.DataSource = task;
                }
                else if (checkboxout.Checked)
                {
                    task = ldtask.GetOutTaskList();
                    dgvCurrentTask.DataSource = task;
                }
                
            }
            else
            {
                trayno = trayno + "%";
                task = ldtask.GetTaskByTrayNo(trayno); 
                dgvCurrentTask.DataSource = task;
            }
            
        }

        private void FormCurrentTask_Load(object sender, EventArgs e)
        {

            checkboxin.Checked=true;
           
        }
    }
}
